package com.tsu.mall.order.mapper;

import com.tsu.mall.common.VO.CartWaresVO;
import com.tsu.mall.order.entity.Cart;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author tttttt
 * @since 2023-04-05
 */
public interface CartMapper extends BaseMapper<Cart> {

    @Select("select * from cart where member_id=#{id} and wares_id=#{waresId} and member_wares_color=#{memberWaresColor} and member_wares_version=#{memberWaresVersion}")
    Cart selectByMemberIDAndWaresID(@Param("id") Integer id, @Param("waresId") Integer waresId, @Param("memberWaresColor") String memberWaresColor, @Param("memberWaresVersion")String memberWaresVersion);

    @Update("update cart set amount=amount+#{waresNum} where id=#{id}")
    void updateAmount(@Param("id")Integer id, @Param("waresNum")Integer waresNum);

    @Select("select wares.id,wares.wares_name,wares.pre_price,wares.price,wares.feature,wares.main_pic,cart.id as cartId,cart.member_id,cart.member_wares_color,cart.member_wares_version,cart.amount\n" +
            "from wares \n" +
            "left join cart on cart.wares_id=wares.id\n" +
            "where cart.member_id=#{currentMemberId}")
    List<CartWaresVO> selectCurrentMemberWaresInfo(Integer currentMemberId);


    @Update("update cart set amount=#{amount} where member_id=#{currentMemberId} and wares_id=#{currentWaresId} and member_wares_color=#{currentColor} and member_wares_version=#{currentVersion} ")
    void doUpdate(@Param("currentMemberId") Integer currentMemberId, @Param("currentWaresId")Integer currentWaresId, @Param("amount")Integer amount, @Param("currentColor")String currentColor, @Param("currentVersion")String currentVersion);

@Select("select * from cart where member_id=#{id}")
    List<Cart> selectCartWaresNumberById(Integer id);
}
